$(function () {
    /**
     * 样式变化
     */
    $(".con_nubmer_span a").click(function () {
      $('.con_nubmer_span a ').css('background','#fff');
      $('.con_nubmer_span a ').css('color', '#000000');
      $(this).css('cssText', ' color:#fff ; background:#57affb');
    });
    $(".left a").click(function () {
        $('.left a ').css('color', '#676869');
        $(this).css('cssText', ' color:#066cb4');
    });
    /**
     * 全选与取消
     */
    $("#selectAll").on("click",function() {
        $(".selectItem").prop("checked", this.checked);
    });
    $(".selectItem").on("click",function() {
        var $items = $(".selectItem");
        $("#selectAll").prop("checked" , $items.length == $items.filter(":checked").length ? true :false);
    });
});

/**
 * 弹窗消息
 * @param content 弹窗内容
 * @param fn 回调函数
 */
function confirmMsg(content,fn) {
    if(content != null && content != "") {
        $.confirm({
            title: '提示',
            content: content,
            confirmButtonClass: 'btn-info',
            animationSpeed: 1000,
            confirm: function () {
                if (typeof fn === "function") {
                    fn.apply();
                }
            }
        });
    }
}
function alertMsg(content,fn) {
    if(content != null && content != "") {
        $.alert({
            content: content,
            confirmButtonClass: 'btn-info',
            animationSpeed: 1000,
            confirm: function () {
                if (typeof fn === "function") {
                    fn.apply();
                }
            }
        });
    }
}

/**
 * 单个删除
 * @param param 参数
 */
function remove(param) {
    if(typeof param === "number"){
        confirmMsg("您确定要删除"+param+"号记录吗！",function() {
            $.ajax({
                type: "POST",
                url: "remove",
                data: "id=" + param,
                timeout: 3000,
                dataType: "text",
                success: function (res) {
                    if(res=="success") {
                        alertMsg("删除成功",function() {window.location.reload();});
                    }else {
                        alertMsg("删除失败！",null);
                    }
                },
                error: function() {
                    alertMsg("操作有误！",function() {window.location.reload();});
                }
            });
        })
    }else {
        alertMsg("操作有误！",null);
    }
}

/**
 * 单个恢复
 * @param param 参数
 */
function recover(param) {
    if(typeof param === "number"){
        confirmMsg("您确定要恢复"+param+"号记录吗！",function() {
            $.ajax({
                type: "POST",
                url: "recover",
                data: "id=" + param,
                timeout: 3000,
                dataType: "text",
                success: function (res) {
                    if(res=="success") {
                        alertMsg("恢复除成功",function() {window.location.reload();});
                    }else {
                        alertMsg("恢复失败！",null);
                    }
                },
                error: function() {
                    alertMsg("操作有误！",function() {window.location.reload();});
                }
            });
        })
    }else {
        alertMsg("操作有误！",null);
    }
}

/**
 * 批量删除
 */
function batchRemove() {
    if($(".selectItem").is(":checked")){
        var $ids = new Array();
        $(".selectItem").filter(":checked").each(function() {
            $ids.push($(this).val())
        });
        confirmMsg("您确定要删除已选的["+$ids+"]记录吗！",function() {
            $.ajax({
                type: "POST",
                url: "removes",
                data: "ids=" + $ids,
                timeout: 3000,
                dataType: "text",
                success: function (res) {
                    if(res=="success") {
                        alertMsg("批量删除成功",function() {window.location.reload();});
                    }else {
                        alertMsg("批量删除失败！",null);
                    }
                },
                error: function() {
                    alertMsg("操作有误！",function() {window.location.reload();});
                }

            });
        })
    }else {
        alertMsg("请选择至少一项！",null);
    }
}


/**
 * 批量删除
 */
function batchRecover() {
    if($(".selectItem").is(":checked")){
        var $ids = new Array();
        $(".selectItem").filter(":checked").each(function() {
            $ids.push($(this).val())
        });
        confirmMsg("您确定要恢复已选的["+$ids+"]记录吗！",function() {
            $.ajax({
                type: "POST",
                url: "recovers",
                data: "ids=" + $ids,
                timeout: 3000,
                dataType: "text",
                success: function (res) {
                    if(res=="success") {
                        alertMsg("批量恢复成功",function() {window.location.reload();});
                    }else {
                        alertMsg("批量恢复失败！",null);
                    }
                },
                error: function() {
                    alertMsg("操作有误！",function() {window.location.reload();});
                }

            });
        })
    }else {
        alertMsg("请选择至少一项！",null);
    }
}

/**
 * 导出信息
 */
function exportInfo() {
    if($(".selectItem").is(":checked")){
        var $ids = "";
        $(".selectItem").filter(":checked").each(function() {
            $ids+=","+$(this).val();
        });
        confirmMsg("您确定要导出已选的["+$ids.substring(1)+"]记录吗！",function() {
            $("#exportParam").val($ids.substring(1));
            $("#exportFr").submit();
        })
    }else {
        alertMsg("请选择至少一项！",null);
    }
}

/**
 * 分页跳转
 */
function goPage(pn) {
    $("#currentPn").attr("value", pn);
    $("#searchFr").submit();
}

/**
 * 分页显示大小变化
 */
function pageSizeChange() {
    var $val = $("#pageSize").val();
    if ($val != null && $val != ""){
        $("#pSize").val($val);
        $("#searchFr").submit();
    }
}
